import { auth } from '@clerk/nextjs/server';
import { redirect } from 'next/navigation';

type Props = {
  params: Promise<{ slug: string }>;
};

export default async function RemasterPage(props: Props) {
  const params = await props.params;
  try {
    const { getToken } = await auth();
    const accessToken = await getToken();

    await fetch(`${process.env.API_BASE}/api/generate/upsample`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${accessToken}`,
      },
      body: JSON.stringify({
        clip_id: params.slug,
      }),
      cache: 'no-store',
    });
  } catch (error) {
    console.error('Error sending remaster request:', error);
  }

  redirect('/create');
}
